home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / Sources / src / origami / screen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  18.5 KB  |  749 lines

  1. /*{{{}}}*/
  2. /*{{{  #includes*/
  3. #ifdef CONFIG_H
  4. #   include "config.h"
  5. #endif
  6.  
  7. #include <sys/types.h>
  8. #include <unistd.h>
  9. #ifdef TERMINFO
  10. #  ifdef INC_CURSES
  11. #     include <curses.h>
  12. #  endif
  13. #  ifdef INC_TERM
  14. #     include <term.h>
  15. #  endif
  16. #  define TERM_DATA_BASE "terminfo"
  17. #else
  18. #  include <termcap.h>
  19. #  define TERM_DATA_BASE "termcap"
  20. #endif
  21. #ifdef TIOCGWINSZ
  22. #  include <sys/ioctl.h>
  23. #endif
  24. #include <termios.h>
  25. #include <limits.h>
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <ctype.h>
  29. #include <string.h>
  30.  
  31. #define SCREEN_C
  32. #define I_BUFFLOOP_C
  33. #define I_DISPLAY_C
  34. #define I_GETMSG_C
  35. #define I_GETTK_C
  36. #define I_KEYBOARD_C
  37. #define I_MAIN_C
  38. #define I_MESSAGES_C
  39. #define I_SIGNALS_C
  40.  
  41. #include "exit.h"
  42. #include "origami.h"
  43. #include <h/envvar_str.h>
  44. /*}}}  */
  45.  
  46. /*{{{  variable declarations*/
  47. private boolean so_active=False;
  48. private boolean so_wished=False;
  49. public char const *terminal=0;
  50. /*{{{  termcap data*/
  51. /*{{{  needed capabilities*/
  52. private char const *term_do_cm;
  53. private char const *term_do_ho;
  54. private char const *term_do_do;
  55. private char const *term_do_n_do;
  56. private char const *term_do_ri;
  57. private char const *term_do_n_ri;
  58. /*}}}  */
  59. /*{{{  optional*/
  60. private char const *term_do_ti;
  61. private char const *term_do_te;
  62. private char const *term_do_ks;
  63. private char const *term_do_ke;
  64. private char const *term_do_cd;
  65. private char const *term_do_cl;
  66. public char const *ce;
  67. private char const *term_do_n_ic;
  68. private char const *term_do_n_dc;
  69. public char const *al;
  70. public char const *dl;
  71. private char const *do_AL;
  72. private char const *do_DL;
  73. private char const *term_do_bl;
  74. private char const *term_do_vb;
  75. private char const *term_do_se;
  76. public char const *so;
  77. private char const *term_do_rp;
  78. #ifdef USE_SCRBUFF
  79. # ifndef BLOCK_FLUSH
  80.      private char const *term_do_im;
  81.      private char const *term_do_ic;
  82.      private char const *term_do_ip;
  83.      private char const *term_do_ei;
  84.      private char const *term_do_dc;
  85.      private char const *term_do_le;
  86.      private char const *term_do_LE;
  87.      private char const *term_do_up;
  88.      private char const *term_do_n_up;
  89.      public boolean mi;
  90. # endif
  91.   private char const *term_do_vi;
  92.   private char const *term_do_vs;
  93. #endif
  94. public boolean am,hz,xs,xt;
  95. public int sg;
  96. /*}}}  */
  97. /*}}}  */
  98. #if defined(USE_SCRBUFF) && !defined(BLOCK_FLUSH)
  99.   public boolean use_shift;
  100. #endif
  101. public FILE *scrout;
  102. public win_data screen;
  103. /*}}}  */
  104.  
  105. /*{{{  t_param_1,t_param_2*/
  106. #ifdef TERMINFO
  107. #  define USE_TPARM
  108. #endif
  109. #ifdef USE_TPARM
  110. # ifdef TPARM_NEEDS_2
  111. #    define t_param_1(f,x1)    (f?(char*)tparm(f,x1,0):(char*)0)
  112. # else
  113. #    define t_param_1(f,x1)    (f?(char*)tparm(f,x1):(char*)0)
  114. #endif
  115. # define t_param_2(f,x1,x2) (f?(char*)tparm(f,x1,x2):(char*)0)
  116. #else
  117.   private char *tg_res;
  118. # define t_goto(f,x1,x2)    (strcmp(tg_res=tgoto(f,x1,x2),"OOPS")?tg_res:(char*)0)
  119. # define t_param_1(f,x1)    (f?(char*)t_goto(f,0,x1):(char*)0)
  120. # define t_param_2(f,x1,x2) (f?(char*)t_goto(f,x2,x1):(char*)0)
  121. #endif
  122. /*}}}  */
  123. /*{{{  outchar*/
  124. private int outchar(int ch)
  125. {
  126.   if (scrout) oputc(ch);
  127.   return(ch);
  128. }
  129. /*}}}  */
  130. /*{{{  move_cursor_to*/
  131. public void move_cursor_to(int y,int x)
  132. {
  133.   if (scrout)
  134.      if (y==1 && x==1 && term_do_ho)
  135.         tputs(term_do_ho,1,outchar);
  136.      else if (term_do_cm)
  137.       /*{{{  use term_do_cm*/
  138.       { char const *s;
  139.  
  140.         if ((s=t_param_2(term_do_cm,y-1,x-1))==0)
  141.            exit(r_init_err);
  142.         tputs(s,1,outchar);
  143.       }
  144.       /*}}}  */
  145.      else
  146.       /*{{{  step by step*/
  147.       { char const *s;
  148.  
  149.         tputs(term_do_ho,1,outchar);
  150.         if (--y>0)
  151.            if ((s=t_param_1(term_do_n_do,y)))
  152.               tputs(s,1,outchar);
  153.            else if (term_do_do)
  154.               do tputs(term_do_do,1,outchar); while (--y);
  155.            else
  156.               exit(r_init_err);
  157.         if (--x>0)
  158.            if ((s=t_param_1(term_do_n_ri,x)))
  159.               tputs(s,1,outchar);
  160.            else if (term_do_ri)
  161.               do tputs(term_do_ri,1,outchar); while (--x);
  162.            else
  163.               exit(r_init_err);
  164.       }
  165.       /*}}}  */
  166. }
  167. /*}}}  */
  168. /*{{{  insLine:  if al known, do and return False, else do nothing and return True*/
  169. public boolean insLine(int n)
  170. {
  171.   if (scrout)
  172.    {
  173. #if defined(USE_SCRBUFF) && !defined(BLOCK_FLUSH)
  174.      char const *s;
  175.  
  176.      if (n>1 && (s=t_param_1(do_AL,n)))
  177.         tputs(s,1,outchar);
  178.      else
  179. #endif
  180.      if (al)
  181.         while (n-->0)
  182.            tputs(al,1,outchar);
  183.      else
  184.         return(True);
  185.    }
  186.  
  187.   return(False);
  188. }
  189. /*}}}  */
  190. /*{{{  DelLine:  if dl known, do and return False, else do nothing and return True*/
  191. public boolean DelLine(int n)
  192. {
  193.   if (scrout)
  194.    {
  195. #if defined(USE_SCRBUFF) && !defined(BLOCK_FLUSH)
  196.      char const *s;
  197.  
  198.      if (n>1 && (s=t_param_1(do_DL,n)))
  199.         tputs(s,1,outchar);
  200.      else
  201. #endif
  202.      if (dl)
  203.         while (n-->0)
  204.            tputs(dl,1,outchar);
  205.      else
  206.         return(True);
  207.    }
  208.  
  209.   return(False);
  210. }
  211. /*}}}  */
  212. #ifdef USE_SCRBUFF
  213. # ifndef BLOCK_FLUSH
  214.      /*{{{  step_or_move_cursor*/
  215.      public void step_or_move_cursor(int y, int x, int dy, int dx)
  216.      {
  217.        if (dx || dy)
  218.         { char const *s;
  219.  
  220.           if
  221.            /*{{{  both diff or no valid capability given*/
  222.            (    (dx&&dy)
  223.              || (dx==1 && (s=term_do_ri)==0)
  224.              || (dx>0 && (s=t_param_1(term_do_n_ri,dx))==0)
  225.              || (dx==-1 && (s=term_do_le)==0)
  226.              || (dx<0 && (s=t_param_1(term_do_LE,-dx))==0)
  227.              || (dy==1 && (s=term_do_do)==0)
  228.              || (dy>0 && (s=t_param_1(term_do_n_do,dy))==0)
  229.              || (dy==-1 && (s=term_do_up)==0)
  230.              || (dy<0 && (s=t_param_1(term_do_n_up,-dy))==0)
  231.            )
  232.            /*}}}  */
  233.              move_cursor_to(y,x);
  234.           else
  235.              tputs(s,1,outchar);
  236.         }
  237.      }
  238.      /*}}}  */
  239.      /*{{{  insChar: return true, if not possible*/
  240.      public void insChar(unsigned char *s,int l)
  241.      {
  242.        if (term_do_im || term_do_ic)
  243.         { if (l)
  244.            { if (term_do_im) tputs(term_do_im,1,outchar);
  245.              do
  246.               { if (term_do_ic) tputs(term_do_ic,1,outchar);
  247.                 oputc(*s);
  248.                 s++;
  249.                 if (term_do_ip) tputs(term_do_ip,1,outchar);
  250.               }
  251.              while (--l);
  252.              if (term_do_ei) tputs(term_do_ei,1,outchar);
  253.            }
  254.         }
  255.      }
  256.      /*}}}  */
  257.      /*{{{  delChar: return True, if not possible*/
  258.      public void delChar(int n)
  259.      {
  260.        if (term_do_dc || term_do_n_dc)
  261.         { char *s;
  262.  
  263.           if (n)
  264.              if ((n>1 || !term_do_dc) && (s=t_param_1(term_do_n_dc,n)))
  265.                 tputs(s,1,outchar);
  266.              else
  267.                 do
  268.                    tputs(term_do_dc,1,outchar);
  269.                 while (--n);
  270.         }
  271.      }
  272.      /*}}}  */
  273. # endif
  274.   /*{{{  cursor*/
  275.   public void scr_cursor(boolean show)
  276.   {
  277.     char const *s;
  278.  
  279.     s=show?term_do_vs:term_do_vi;
  280.     if (s)
  281.        tputs(s,1,outchar);
  282.   }
  283.   /*}}}  */
  284. #endif
  285. /*{{{  moputc*/
  286. #ifdef BLOCK_FLUSH
  287. private
  288. #else
  289. public
  290. #endif
  291.         int moputc(int c,int n)
  292. {
  293.   if (scrout)
  294.      if (n>0)
  295.       { char *s;
  296.  
  297.         if ((n>M_RP_LIMIT) && (s=t_param_2(term_do_rp,(int)c,n)))
  298.            tputs(s,1,outchar);
  299.         else
  300.         if
  301.          (    !so_active
  302.            && c==' '
  303.            && n>M_DIR_RP_LIMIT
  304.            && t_param_1(term_do_n_ic,n)
  305.            && (s=t_param_1(term_do_n_dc,n))
  306.          )
  307.          { if (n<screen.w) tputs(s,1,outchar);
  308.            tputs(t_param_1(term_do_n_ic,n),1,outchar);
  309.            return(n);
  310.          }
  311.         else
  312.            do
  313.               oputc(c);
  314.            while (--n);
  315.       }
  316.  
  317.   return(0);
  318. }
  319. /*}}}  */
  320. /*{{{  init_terminal*/
  321. public void init_terminal(void)
  322. {
  323.   if (term_do_ti)
  324.      tputs(term_do_ti,1,outchar);
  325.   switch (kp_state)
  326.    { case 'A':
  327.      case 'a':
  328.      default:
  329.         if (term_do_ks)
  330.          { tputs(term_do_ks,1,outchar);
  331.            fflush(stdout);
  332.          }
  333.      case 'N':
  334.      case 'n':
  335.         break;
  336.    }
  337. }
  338. /*}}}  */
  339. /*{{{  reset_terminal*/
  340. public void reset_terminal(void)
  341. {
  342.   move_cursor_to(screen.h,1);
  343.   oputc('\n');
  344.   switch (kp_state)
  345.    { case 'A':
  346.      case 'a':
  347.      default:
  348.         if (term_do_ke)
  349.          { tputs(term_do_ke,1,outchar);
  350.            fflush(stdout);
  351.          }
  352.      case 'N':
  353.      case 'n':
  354.         break;
  355.    }
  356.   if (term_do_te) tputs(term_do_te,1,outchar);
  357.   fflush(stdout);
  358. }
  359. /*}}}  */
  360. /*{{{  do_standout*/
  361. public void do_standout(void)
  362. {
  363.   if (so)
  364.    { so_wished=True;
  365.      if (scrout)
  366.       { so_active=True;
  367.         tputs(so,1,outchar);
  368.       }
  369.    }
  370. }
  371. /*}}}  */
  372. /*{{{  do_standend*/
  373. public void do_standend(void)
  374. {
  375.   if (term_do_se)
  376.    { so_wished=False;
  377.      if (scrout)
  378.       { so_active=False;
  379.         tputs(term_do_se,1,outchar);
  380.       }
  381.    }
  382. }
  383. /*}}}  */
  384. /*{{{  moveclreol*/
  385. public void moveclreol(int y,int x)
  386. { if (scrout)
  387.    { move_cursor_to(y,x);
  388.      if (ce)
  389.         tputs(ce,1,outchar);
  390.      else
  391.       { if (am && (y==screen.h)) x++;
  392.         moputc(' ',screen.w-x);
  393.       }
  394.    }
  395. }
  396. /*}}}  */
  397. /*{{{  clrscr*/
  398. public void ClrScr(void)
  399. {
  400.   if (scrout)
  401.      if (term_do_cl)
  402.         tputs(term_do_cl,1,outchar);
  403.      else if (term_do_ho && term_do_cd)
  404.       /*{{{  home and clear to end of display*/
  405.       { tputs(term_do_ho,1,outchar);
  406.         tputs(term_do_cd,screen.h,outchar);
  407.       }
  408.       /*}}}  */
  409.      else
  410.       /*{{{  clear line by line*/
  411.       { int i;
  412.  
  413.         for (i=1;i<=screen.h;moveclreol(i++,1));
  414.         if (am) outchar(' ');
  415.       }
  416.       /*}}}  */
  417. }
  418. /*}}}  */
  419. /*{{{  bell_audible*/
  420. public void bell_audible(void)
  421. {
  422.   if (term_do_bl && scrout)
  423.    { tputs(term_do_bl,1,outchar);
  424.      fflush(scrout);
  425.    }
  426. }
  427. /*}}}  */
  428. /*{{{  bell_visible*/
  429. public void bell_visible(void)
  430. {
  431.   if (term_do_vb && scrout)
  432.    { tputs(term_do_vb,1,outchar);
  433.      fflush(scrout);
  434.    }
  435. }
  436. /*}}}  */
  437. /*{{{  send_terminal*/
  438. public void send_terminal(int c)
  439. {
  440.   putc(c,stdout);
  441. }
  442. /*}}}  */
  443. /*{{{  flush_terminal*/
  444. public void flush_terminal(void)
  445. {
  446.    fflush(stdout);
  447. }
  448. /*}}}  */
  449. /*{{{  check_terminal*/
  450. public boolean check_terminal(char const * const t)
  451. {
  452.   int l;
  453.   boolean ok;
  454.  
  455.   ok=False;
  456.   if (t[l=(strlen(t)-1)]=='*')
  457.    { if (!strncmp(terminal,t,l-1)) ok=True; }
  458.   else
  459.    { if (!strcmp(terminal,t)) ok=True; }
  460.  
  461.   return(ok);
  462. }
  463. /*}}}  */
  464. /*{{{  screen_off*/
  465. public void screen_off(void)
  466. { scrout=0;
  467. }
  468. /*}}}  */
  469. /*{{{  screen_on*/
  470. public void screen_on(void)
  471. {
  472.   scrout=stdout;
  473.   if (so_wished!=so_active) if (so_wished) do_standout(); else do_standend();
  474. }
  475. /*}}}  */
  476. /*{{{  get_terminal_capability*/
  477. #if (defined(MOUSY) && defined(XTERM))
  478.    /*{{{  xterm_size*/
  479.    private boolean xterm_size(char const * const t)
  480.    {
  481.      if (!strcmp(t,XTERM_MOUSE_NAME) && isatty(fileno(stdout)))
  482.       /*{{{  try to get from xterm*/
  483.         for (;;)
  484.          { char b[32];
  485.            char *d,*s;
  486.  
  487.            /*{{{  activate the sending*/
  488.            fputs(XTERM_GET_SIZE,stdout);
  489.            fflush(stdout);
  490.            /*}}}  */
  491.            /*{{{  read the header*/
  492.            s=XTERM_SIZE_HEAD;
  493.            while (*s && (read_err(kbd_file,b),b[0]==*s)) s++;
  494.            if (*s) break;
  495.            /*}}}  */
  496.            /*{{{  get lines*/
  497.            d=b;
  498.            while (isdigit((read_err(kbd_file,d),*d++)));
  499.            if (*--d!=XTERM_SIZE_MID[0]) break;
  500.            *d=0;
  501.            screen.h=atoi(b);
  502.            /*}}}  */
  503.            /*{{{  get rest of mid text*/
  504.            s=XTERM_SIZE_MID+1;
  505.            while (*s && (read_err(kbd_file,b),b[0]==*s)) s++;
  506.            /*}}}  */
  507.            /*{{{  get columns*/
  508.            d=b;
  509.            while (isdigit((read_err(kbd_file,d),*d++)));
  510.            if (*--d!=XTERM_SIZE_END[0]) break;
  511.            *d=0;
  512.            screen.w=atoi(b);
  513.            /*}}}  */
  514.            /*{{{  get rest of end text*/
  515.            s=XTERM_SIZE_END+1;
  516.            while (*s && (read_err(kbd_file,b),b[0]==*s)) s++;
  517.            /*}}}  */
  518.            return(False);
  519.          }
  520.       /*}}}  */
  521.      return(True);
  522.    }
  523.    /*}}}  */
  524. #   define no_xterm_size xterm_size(terminal)
  525. #else
  526. #   define no_xterm_size 1
  527. #endif
  528.  
  529. public int get_terminal_capability(void)
  530. {
  531.   /*{{{  terminal data variables*/
  532. #  ifdef TIOCGWINSZ
  533.      int res;
  534.      struct winsize winsz;
  535. #  endif
  536. #  ifdef TERMINFO
  537.      int result;
  538. #    define GET_TERM_STR(cap,info) info
  539. #    define GET_TERM_VAL(cap,info) info
  540. #    define GET_TERM_TAG(cap,info) info
  541. #    define GET_DATABASE(term) (setupterm(term,2,&result),resetterm(),result)
  542. #    define INIT_DATABASE()
  543. #  else
  544.      static char termcap_area[512];
  545.      static char bp[1024];
  546.      static char *pointer;
  547. #    define GET_TERM_STR(cap,info) tgetstr(cap,&pointer)
  548. #    define GET_TERM_VAL(cap,info) tgetnum(cap)
  549. #    define GET_TERM_TAG(cap,info) tgetflag(cap)
  550. #    define GET_DATABASE(term) tgetent(bp,term)
  551. #    define INIT_DATABASE() pointer=termcap_area
  552. #  endif
  553.   /*}}}  */
  554.  
  555.   if (!terminal)
  556.    /*{{{  first call => get terminal dependent strings*/
  557.    {
  558.      /*{{{  get terminal name*/
  559.      if (!(terminal=getenv(TERM)))
  560. #       ifdef DEFAULT_TERM
  561.            terminal=DEFAULT_TERM;
  562. #       else
  563.          { oputs((char *)get_msg(M_NO_TERM));
  564.            return(1);
  565.          }
  566. #       endif
  567.      /*}}}  */
  568.      /*{{{  read termcap data*/
  569.      switch (GET_DATABASE(terminal))
  570.       { case -1: { oputs((char *)get_msg(F_NO_TERMCAP,TERM_DATA_BASE));return (1); }
  571.         case  0: { oputs((char *)get_msg(F_TERMB,terminal,TERM_DATA_BASE));return (1); }
  572.       }
  573.      INIT_DATABASE();
  574.      /*}}}  */
  575.      /*{{{  get needed features*/
  576.      /*{{{  cursor motion*/
  577.      /*{{{  cursor move*/
  578.      term_do_cm=GET_TERM_STR("cm",cursor_address);
  579.      /*}}}  */
  580.      /*{{{  home*/
  581.      term_do_ho=GET_TERM_STR("ho",cursor_home);
  582.      /*}}}  */
  583.      /*{{{  down*/
  584.      term_do_do=GET_TERM_STR("do",cursor_down);
  585.      /*}}}  */
  586.      /*{{{  down**/
  587.      term_do_n_do=GET_TERM_STR("DO",parm_down_cursor);
  588.      /*}}}  */
  589.      /*{{{  right*/
  590.      term_do_ri=GET_TERM_STR("nd",cursor_right);
  591.      /*}}}  */
  592.      /*{{{  right**/
  593.      term_do_n_ri=GET_TERM_STR("RI",parm_right_cursor);
  594.      /*}}}  */
  595.      if (!term_do_cm && !(term_do_ho && (term_do_do || term_do_n_do) && (term_do_ri || term_do_n_ri)))
  596.       { oputs((char *)get_msg(F_TERMA,"cursor motion (cm)",terminal));
  597.         exit(r_init_err);
  598.       }
  599.      /*}}}  */
  600.      /*{{{  screen size*/
  601. #     ifdef TIOCGWINSZ
  602.         if (ioctl(0,TIOCGWINSZ,&winsz)!=-1)
  603.          { screen.h=winsz.ws_row;
  604.            screen.w=winsz.ws_col;
  605.          }
  606. #     endif
  607.      if (screen.h<=0)
  608.         screen.h=GET_TERM_VAL("li",lines);
  609.      if (screen.w<=0)
  610.         screen.w=GET_TERM_VAL("co",columns);
  611.      if (screen.h<=0 || screen.w<=0)
  612.       { oputs((char *)get_msg(F_TERMA,STR_WINSIZE,terminal));
  613.         exit(r_init_err);
  614.       }
  615.      /*}}}  */
  616.      /*}}}  */
  617.      /*{{{  get optional features*/
  618.      /*{{{  init/reset terminal*/
  619.      term_do_ti=GET_TERM_STR("ti",enter_ca_mode);
  620.      term_do_te=GET_TERM_STR("te",exit_ca_mode);
  621.      /*}}}  */
  622.      /*{{{  clear's*/
  623.      ce=GET_TERM_STR("ce",clr_eol);
  624.      term_do_cl=GET_TERM_STR("cl",clear_screen);
  625.      term_do_cd=GET_TERM_STR("cd",clr_eos);
  626.      /*}}}  */
  627.      /*{{{  add/delete line*/
  628.      al=GET_TERM_STR("al",insert_line);
  629.      do_AL=GET_TERM_STR("AL",parm_insert_line);
  630.      dl=GET_TERM_STR("dl",delete_line);
  631.      do_DL=GET_TERM_STR("DL",parm_delete_line);
  632.      /*}}}  */
  633.      /*{{{  bells*/
  634.      term_do_bl=GET_TERM_STR("bl",bell);
  635.      term_do_vb=GET_TERM_STR("vb",flash_screen);
  636.      /*}}}  */
  637.      /*{{{  keypad*/
  638.      term_do_ks=GET_TERM_STR("ks",keypad_xmit);
  639.      term_do_ke=GET_TERM_STR("ke",keypad_local);
  640.      /*}}}  */
  641.      /*{{{  standout*/
  642.      /*{{{  get standout glitches*/
  643.      if ((sg=GET_TERM_VAL("sg",magic_cookie_glitch))==-1)
  644.         sg=0;
  645.      xs=GET_TERM_TAG("xs",ceol_standout_glitch);
  646.      xt=GET_TERM_TAG("xt",teleray_glitch);
  647. #     ifdef USE_SCRBUFF
  648. #       ifndef BLOCK_FLUSH
  649.            mi=GET_TERM_TAG("mi",move_insert_mode);
  650. #       endif
  651. #     endif
  652.      /*}}}  */
  653.      if
  654.       (
  655. #     ifndef USE_SCRBUFF
  656.               xt || xs ||
  657. #     endif
  658.         (    (    !(so=GET_TERM_STR("so",enter_standout_mode))
  659.                || !(term_do_se=GET_TERM_STR("se",exit_standout_mode))
  660.              )
  661.           && (    !(so=GET_TERM_STR("mr",enter_reverse_mode))
  662.                || !(term_do_se=GET_TERM_STR("me",exit_attribute_mode))
  663.              )
  664.           && (    !(so=GET_TERM_STR("us",enter_underline_mode))
  665.                || !(term_do_se=GET_TERM_STR("ue",exit_underline_mode))
  666.              )
  667.         )
  668.       )
  669.         so=term_do_se=0;
  670.      /*}}}  */
  671.      /*{{{  repeat character*/
  672.      term_do_rp=GET_TERM_STR("rp",repeat_char);
  673.      /*}}}  */
  674.      /*{{{  cursor*/
  675. #     ifdef USE_SCRBUFF
  676.         term_do_vi=GET_TERM_STR("vi",cursor_invisible);
  677.         term_do_vs=GET_TERM_STR("vs",cursor_visible);
  678.         if (term_do_vi && !term_do_vs)
  679.            term_do_vs=GET_TERM_STR("ve",cursor_normal);
  680.         else if (!term_do_vi && term_do_vs)
  681.            term_do_vi=GET_TERM_STR("ve",cursor_normal);
  682.         if (!term_do_vs)
  683.            term_do_vi=0;
  684.         else if (!term_do_vi)
  685.            term_do_vs=0;
  686. #     endif
  687.      /*}}}  */
  688. #     if defined(USE_SCRBUFF) && !defined(BLOCK_FLUSH)
  689.       /*{{{  additional cursor movements*/
  690.         term_do_up=GET_TERM_STR("up",cursor_up);
  691.         term_do_n_up=GET_TERM_STR("UP",parm_up_cursor);
  692.         term_do_le=GET_TERM_STR("le",cursor_left);
  693.         term_do_LE=GET_TERM_STR("LE",parm_left_cursor);
  694.       /*}}}  */
  695. #     endif
  696.      if (!GET_TERM_TAG("in",insert_null_glitch))
  697.       /*{{{  read insert/delete character stuff*/
  698.       { term_do_n_ic=GET_TERM_STR("IC",parm_ich);
  699.         term_do_n_dc=GET_TERM_STR("DC",parm_dch);
  700. #       if defined(USE_SCRBUFF) && !defined(BLOCK_FLUSH)
  701.            term_do_im=GET_TERM_STR("im",enter_insert_mode);
  702.            term_do_ic=GET_TERM_STR("ic",insert_character);
  703.            term_do_ip=GET_TERM_STR("ip",insert_padding);
  704.            term_do_ei=GET_TERM_STR("ei",exit_insert_mode);
  705.            term_do_dc=GET_TERM_STR("dc",delete_character);
  706. #       endif
  707.       }
  708.       /*}}}  */
  709.      /*}}}  */
  710.      /*{{{  check some strange features*/
  711. #     if defined(USE_SCRBUFF) && !defined(BLOCK_FLUSH)
  712.         use_shift=False;
  713.         if ((term_do_im || term_do_ic) && (term_do_dc || term_do_n_dc) && !xs)
  714.            use_shift=True;
  715. #     endif
  716.      am=GET_TERM_TAG("am",auto_right_margin);
  717.      hz=GET_TERM_TAG("hz",tilde_glitch);
  718.      /*}}}  */
  719.    }
  720.    /*}}}  */
  721.   else
  722.    /*{{{  get window-size*/
  723.    { if (no_xterm_size)
  724.       {
  725. #       ifdef TIOCGWINSZ
  726.            res=ioctl(0,TIOCGWINSZ,&winsz);
  727.            screen.h=(res==-1 || winsz.ws_row<=0)
  728.                      ? GET_TERM_VAL("li",lines)
  729.                      : winsz.ws_row;
  730.            screen.w=(res==-1 || winsz.ws_col<=0)
  731.                       ? GET_TERM_VAL("co",columns)
  732.                       : winsz.ws_col;
  733. #       else
  734.            screen.h=GET_TERM_VAL("li",lines);
  735.            screen.w=GET_TERM_VAL("co",columns);
  736. #       endif
  737.       }
  738.    }
  739.    /*}}}  */
  740.   /*{{{  minimum window is 1x1*/
  741.   if (screen.h<=0)
  742.      screen.h=1;
  743.   if (screen.w<=0)
  744.      screen.w=1;
  745.   /*}}}  */
  746.   return (0);
  747. }
  748. /*}}}  */
  749.